package com.hy.myapp.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import com.hy.myapp.Entity.Reputation;

@Mapper
public interface ReputationMapper {
	/**
	 * 加一个成名
	 * @param fname
	 * @return
	 */
	@Insert(" insert into mc_reputation(id,name,create_uid) values(mc_reputation_id_sqs.nextval,#{name},#{userid}) ")
	int add(@Param("name") String fname,@Param("userid") long userid);
	
	/**
	 * 加一个成名及其描述
	 * @param fname
	 * @return
	 */
	@Insert(" insert into mc_reputation(id,name,brief,create_uid) values(mc_reputation_id_sqs.nextval,#{name},#{desc},#{userid}) ")
	int add2(@Param("name") String name,@Param("desc") String desc,@Param("userid") long userid);
	
	/**
	 * 计算既存成名数量
	 * @param fname
	 * @return
	 */
	@Select(" select count(*) from mc_reputation where name=#{name} ")
	int count(@Param("name") String fname);
	
	/**
	 * 查询所有的成名，只要名称
	 * @return
	 */
	@Select(" select name from mc_reputation order by id ")
	List<String> queryAllNames();
	
	/**
	 * 查询全部成名，活的死的都要
	 * @return
	 */
	@Select("select a.id,a.name,a.brief,a.deleted,to_char(a.create_time,'yyyy-mm-dd hh24:mi:ss') as ctime,b.name as creater from mc_reputation a left join mc_user b on a.create_uid=b.id order by a.id ")
	List<Reputation> queryAll();
	
	/**
	 * 查询活的（deleted=0）全部成名
	 * @return
	 */
	List<Reputation> queryAliveAll();
	
	/**
	 * 查询死的（deleted=1）全部成名
	 * @return
	 */
	@SelectProvider(type=ReputationMapperSql.class,method="getQueryDeadAllSql")
	List<Reputation> queryDeadAll();
	
	// 查活成名总数
	@Select(" select count(*) from mc_reputation where deleted=0 and name like #{kwName} ")
	int countAlive(@Param("kwName") String keyword);
	
	/**
	 * 分页查询活的成名
	 * @param start
	 * @param end
	 * @return
	 */
	@SelectProvider(type=ReputationMapperSql.class,method="getPagedQueryAliveSql")
	List<Reputation> pagedQueryAlive(String keyword,int start,int end);
}
